package com.jhh.pay.driver;

import java.util.List;

import com.ecwid.consul.v1.ConsulClient;
import com.ecwid.consul.v1.QueryParams;
import com.ecwid.consul.v1.Response;
import com.ecwid.consul.v1.health.model.HealthService;

import lombok.extern.slf4j.Slf4j;

//@SpringBootApplication
//@EnableAutoConfiguration
//@ComponentScan("com.jhh.pay")
@Slf4j
public class Application {
	
	
	public static void main(String[] args) {
//		ConfigurableApplicationContext cac = SpringApplication.run(Application.class, args);
//		
//		cac.addApplicationListener(new ApplicationListener<ContextClosedEvent>() {
//
//			@Override
//			public void onApplicationEvent(ContextClosedEvent event) {
//				if(logger.isDebugEnabled()) {
//					logger.debug("--------------------ContextClosed-------------------");
//				}
//			}
//		});
//		
//		DiscoveryService discoveryService = cac.getBean(DiscoveryService.class);
//		System.out.println(discoveryService.serviceUrl());
		ConsulClient client = new ConsulClient("192.168.1.101:8500");
		Response<List<HealthService>> healthyServices = client.getHealthServices("pay-center", true, QueryParams.DEFAULT);
		log.info(String.valueOf(healthyServices.getValue().size()));
		for(HealthService healthService : healthyServices.getValue()) {
			log.info("------------------------------------------------");
			log.info(healthService.getService().toString());
			log.info(healthService.getNode().toString());
			log.info(healthService.getService().getAddress()+":"+healthService.getService().getPort());
			log.info("------------------------------------------------");
		}
    }
}
